/***************************************************************************
 *            protocol.h
 *
 *  Fri Dec  4 11:13:03 2009
 *  Copyright  2009  simone vellei
 *  <henomis@gmail.com>
 ****************************************************************************/

/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
 */

#ifndef _PROTOCOL_H_
#define _PROTOCOL_H_

#define PROTO_ERR 1

#define PACKET_SENDCMD 0

/*
 *
 * +---------+
 * | HEADER  |
 * +---------+
 * | COMMAND |
 * |         |
 * +---------+
 * |         |
 * | ARMOR   |
 * |         |
 * |         |
 * +---------+
 *
 */

/*typedef union paket_data {

	unsigned char raw[23];
}*/

typedef struct packet {

	union data {
		struct field {
			unsigned char header;
			unsigned char command;
			unsigned char notused; // If I need more than 255 commands
			unsigned int  seqnum;
			unsigned char armor[20];
		}field;
		unsigned char raw[23];
	}data;

	// only to pass the key
	unsigned char key[20];
	
} packet_t;

void init_packet(packet_t *pkt, unsigned char *key);
void prepare_packet(packet_t *pkt, unsigned char header, unsigned char command, unsigned char doprng, unsigned int prng);
unsigned char check_packet(packet_t *pkt, unsigned char *key, unsigned int last_seqnum);
void info_packet(packet_t *pkt);

#endif
